<?php

/*
 * 	Codificado: 02-Noviembre-2011, 00:31
	Estado: Ajustado_Modelo_Actual(X) Funcionando()
 */


class Convenios_Lineas_Model extends CI_Model{

	private $table = 'Convenios_Lineas';

	function _required($required, $data)
	{
		foreach($required as $field)
		if(!isset($data[$field])) return false;

		return true;
	}



	function Insertar($option = array()) {
		if ($this->_required(array('IdConvenios','IdLineas'), $options)) return FALSE ;

		$this->db->insert($this->table, $options);
		return $this->db->insert_id();

	}

	function Editar($options = array()) {
		if(!$this->_required(array('IdConvenios', 'IdLineas'),$options))
		return FALSE;

		unset($options['submit'] );

		if(isset($options['IdConvenios']))
		$this->db->set('IdConvenios', $options['IdConvenios']);

		if(isset($options['IdLineas']))
		$this->db->set('IdLineas', $options['IdLineas']);

		if(isset($options['Observaciones']))
		$this->db->set('Observaciones', $options['Observaciones']);

		$this->db->where('IdConvenios', $options['IdConvenios']);
		$this->db->where('IdLineas', $options['IdLineas']);
		$this->db->update($this->table, $options);

		return $this->db->affected_rows();
	}

	function Eliminar($options = array()) {

		$this->db->where('IdConvenios', $options['IdConvenios']);
		$this->db->where('IdLineas', $options['IdLineas']);
		$this->db->delete($this->table);

		if($data['error'] = $this->db->_error_message());

		return $data;

	}

	function Ver($options = array()) {

		$query = $this->db->get($this->table);

		return $query->result_array();
	}

	function Listar($options = array()) {

		$this->db->select('Id,IdConvenios,IdLineas' );

		if(isset($options['limit']) && isset($options['offset']))
		$this->db->limit($options['limit'], $options['offset']);
		else if(isset($options['limit']))
		$this->db->limit($options['limit']);
			
		$query = $this->db->get($this->table);
		if(isset($options['count']))
		return $query->num_rows();
			
		return $query->result_array();
	}

	function BuscarPorIdConvenios($options = array()) {
		if ($this->_required(array('IdConvenios'), $options)) return FALSE ;

		$this->db->where('IdConvenios', $options['IdConvenios']);
		$query = $this->db->get($this->table);

		return $query->result_array();
	}

	function BuscarPorIdLineas($options = array()) {
		if ($this->_required(array('IdLineas'), $options)) return FALSE ;

		$this->db->where('IdLineas', $options['IdLineas']);
		$query = $this->db->get($this->table);

		return $query->result_array();
	}

}